//
//  TouchView.m
//  UI29_Block
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 lanou.com. All rights reserved.
//

#import "TouchView.h"

@interface TouchView ()

@property (strong, nonatomic) IBOutlet TouchView *view;

@property (nonatomic, copy) void (^block) (TouchView *);



@property (nonatomic, copy) void (^deleteButton)(UIButton *);


@property (nonatomic, copy) void (^addButton)(UIButton *button);

@end

@implementation TouchView

- (instancetype)initWithCoder:(NSCoder *)aDecoder {

    self = [super initWithCoder:aDecoder];
    if (self) {
        [[NSBundle mainBundle]loadNibNamed:@"TouchView" owner:self options:nil];
        
        
        self.view.frame = self.bounds;
        [self addSubview:self.view];
    }

    return  self;
}


- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    // 点击之后调用block
    self.block(self);
    
}

// 实现带block参数的方法.
- (void)viewDidClick:(void (^)(TouchView *))block {

    self.block = block;

}

- (void)buttonHandle:(void (^)(UIButton *button))block {
    self.deleteButton = block;


}

- (void)addButtonHandle:(void(^)(UIButton *addButton)) block1 deleteButtonHandle:(void(^)(UIButton *deleteButton)) block2 {

    self.deleteButton = block2;
    self.addButton = block1;

}



// 点击删除的button.
- (IBAction)handleButtonAction:(id)sender {
    
    self.deleteButton((UIButton *)sender);
    
    
}
// 点击添加的button.
- (IBAction)handleAdd:(UIButton *)sender {
    
    self.addButton(sender);
    
}


@end
